//
//  ClassCollectionReusableView.m
//  UI14_UICollectionViewText(半塘晒单)
//
//  Created by Hanlingyu on 16/8/2.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "ClassCollectionReusableView.h"
#import "ClassesCollectionViewCell.h"
#define kReuse @"reuse"
#define kCollectionViewHeaderReusable @"kCollectionViewReusable"
@interface ClassCollectionReusableView ()
<
UICollectionViewDataSource,
UICollectionViewDelegate
>

@property (nonatomic, strong) UICollectionView *myCollectionView;

@end

@implementation ClassCollectionReusableView

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(self.bounds.size.width / 2 - 7.5, 400 / 3 - 7.5);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumLineSpacing = 5;
    layout.minimumInteritemSpacing = 5;
    layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    
//    layout.itemSize = CGSizeMake(self.bounds.size.width / 2 - 5, self.bounds.size.width / 3 - 5);
    _myCollectionView = [[UICollectionView alloc] initWithFrame: self.frame collectionViewLayout:layout];
    _myCollectionView.backgroundColor = [UIColor yellowColor];
    [self addSubview:_myCollectionView];
    _myCollectionView.dataSource = self;
    _myCollectionView.delegate = self;
    
    [_myCollectionView registerClass:[ClassesCollectionViewCell class] forCellWithReuseIdentifier:kReuse];
    [_myCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCollectionViewHeaderReusable];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 10;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    ClassesCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kReuse forIndexPath:indexPath];
    cell.backgroundColor = [UIColor yellowColor];
    return cell;
    
    
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    
    UICollectionReusableView *reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCollectionViewHeaderReusable forIndexPath:indexPath];
    reusableView.backgroundColor = [UIColor redColor];
    return reusableView;

    
    
}


@end
